/*
* 实现一种算法，找出单向链表中倒数第 k 个节点。返回该节点的值。
* https://leetcode.cn/problems/kth-node-from-end-of-list-lcci/
* */
class KthToLast {
    public int kthToLast(ListNode head, int k) {
        ListNode fast=head;
        ListNode slow=head;
        while(k-1>0){
            k--;
            fast=fast.next;
        }
        while(fast.next!=null){
            fast=fast.next;
            slow=slow.next;
        }
        return slow.val;
    }
}